package state

func (this *luaState) Len(idx int) {
	val := this.stack.get(idx)
	if s, ok := val.(string); ok {
		this.stack.push(int64(len(s)))
	} else if t, ok := val.(*LuaTable); ok {
		this.stack.push(int64(t.Len()))
	} else {
		panic("len() arg is not string")
	}
}

func (this *luaState) Concat(n int) {
	if n == 0 {
		this.stack.push("")
	} else if n >= 2 {
		lastS := ""
		for n > 0 {
			if !this.IsString(-1) {
				panic("concat stack top is not string type")
			}
			str := this.ToString(-1)
			this.stack.pop()
			lastS = str + lastS
			n--
		}
		this.stack.push(lastS)
	}
}
